using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace PrintBarcode
{
    public partial class print_barcode_new : UTLBASEFORM.MDICHILD
    {
        DataTable data;
        TProduct1 tProduct = new TProduct1();
        ReportDocument rptAllCustomersOrders = new ReportDocument();
        public print_barcode_new()
        {
            InitializeComponent();
        }
        private void print_barcode_new_Load(object sender, EventArgs e)
        {
            setupMenu();
            LoadProduct();
        }
        public void LoadProduct()
        {
            lvProduct.Items.Clear();
            data = tStamp.SetData();

            for (int i = 0; i < data.Rows.Count; i++)
            {
                int stt = i + 1;
                ListViewItem item = new ListViewItem(stt.ToString());

                lvProduct.Items.Add(item);

                // item.SubItems.Add(stt.ToString());

                item.SubItems.Add(data.Rows[i]["NamePr"].ToString());
                item.SubItems.Add(data.Rows[i]["Barcode"].ToString());
                item.SubItems.Add(data.Rows[i]["Weight"].ToString());

                item.SubItems.Add(data.Rows[i]["GoldType"].ToString());
                item.SubItems.Add(data.Rows[i]["NameUnit"].ToString().Trim());
                item.SubItems.Add(data.Rows[i]["CreateDate"].ToString());
                item.SubItems.Add(data.Rows[i]["ID"].ToString());

                if (i % 2 == 0)
                {
                    item.BackColor = Color.AliceBlue;
                    //return ;
                }
                else
                {
                    item.BackColor = Color.AntiqueWhite;
                    //return Brushes.Beige;
                }

            }
        }
        private void hienthi(string sid)
        {
            string localPath = Application.StartupPath;
            string cc = @"..\..\reports\rptprintbarcode.rpt";
            rptAllCustomersOrders.Load(cc);
            //rptAllCustomersOrders.Load("rpt_report_kd.rpt");
            ReportDAO rpt = new ReportDAO();

            rpt.kenoi(rptAllCustomersOrders);

            CrystalDecisions.Shared.ParameterDiscreteValue pdvCustomerName1 = new CrystalDecisions.Shared.ParameterDiscreteValue();
            //CrystalDecisions.Shared.ParameterDiscreteValue pdvCustomerName2 = new CrystalDecisions.Shared.ParameterDiscreteValue();

            CrystalDecisions.Shared.ParameterValues pvCollection1 = new CrystalDecisions.Shared.ParameterValues();
            //CrystalDecisions.Shared.ParameterValues pvCollection2 = new CrystalDecisions.Shared.ParameterValues();

            pdvCustomerName1.Value = sid;
            //pdvCustomerName2.Value = dateTimePicker1.Value.Year;

            // Add it to the parameter collection.


            pvCollection1.Add(pdvCustomerName1);
            // pvCollection2.Add(pdvCustomerName2);

            // Apply the current parameter values.

            rptAllCustomersOrders.DataDefinition.ParameterFields["@sid"].ApplyCurrentValues(pvCollection1);
            //rptAllCustomersOrders.DataDefinition.ParameterFields["@year"].ApplyCurrentValues(pvCollection2);

            // Hide group tree for this report


            crystalReportViewer1.ReportSource = rptAllCustomersOrders;

            crystalReportViewer1.Refresh();
            crystalReportViewer1.Zoom(1);


        }

        private void setupMenu()
        {
            ShowBTN1("Xem", "");
            ShowBTN2("In", "");
            ShowBTN3("Lam Lai", "");
        }
        public override void btn1_Click(object sender, EventArgs e)
        {
            PrintStamp();
        }
        public override void btn2_Click(object sender, EventArgs e)
        {
            crystalReportViewer1.PrintReport();
        }
        public override void btn3_Click(object sender, EventArgs e)
        {
            crystalReportViewer1.PrintReport();
        }

       

        private void button1_Click_1(object sender, EventArgs e)
        {
            //string sid;
            //sid = "";
            //for (int i = 0; i < lvProduct.Items.Count; i++)
            //{
            //    if (lvProduct.Items[i].Selected)
            //    {
            //        sid = sid + lvProduct.Items[i].SubItems[7].Text + ",";
            //    }
            //}

            //if (sid.EndsWith(",") == true)
            //    sid = sid.Substring(0, sid.Length - 1);

            //hienthi(sid);
            PrintStamp();
        
        }
        public void PrintStamp() {

          //  BUS.TStamp tStamp = new BUS.TStamp();
            BUS.TStampAll tStamp = new BUS.TStampAll();
            DataSet ds = new DataSet();
            DataTable dt = tStamp.SetData();
            ds.Tables.Add(dt);
            rptStampAll rpt = new rptStampAll();
          //  rptStamp rpt = new rptStamp();
            rpt.SetDataSource(ds.Tables[0]);
            crystalReportViewer1.ReportSource = rpt;
            crystalReportViewer1.Refresh();
            
       }

       

       
        

    }
}

